/**
 * Urban Parks 
 *
 * Team M&M'S 
 * Michael Pogson
 * Michael Satran Jr.
 * Stehpen Hunter
 * 
 * Date: ${date}
 */

package model;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 * 
 * @author Stephen Hunter
 * @version Winter 2012
 */
public class Park {
	
	/**
	 * The list of jobs at this park.
	 */
	private final Collection<Job> my_jobs = new ArrayList<Job>();
	
	/**
	 * The name of the park.
	 */
	private String my_name;
	
	/**
	 * The district this park is located in.
	 */
	private String my_district;
	
	/**
	 * The region this park is located in.
	 */
	private String my_region;
	
	/*
	 * @pre the_parkName != null
	 * @pre the_district != null
	 * @pre the_region != null
	 * 
	 * @post my_jobs will contain all jobs in the_jobs
	 * @post my_name == the_name
	 * @post my_district == the_district
	 * @post my_region == the_region
	 */
	/**
	 * Constructor creates a park object with the given parameters.
	 * 
	 * @param the_jobs A list of jobs to be added to this park's job list
	 * @param the_name The name to set as the name of this park
	 * @param the_district The district to set as this park's district
	 * @param the_region The region to set as this park's region
	 * @throws IllegalArgumentException if any of the parameters are null
	 */
	public Park(final Collection<Job> the_jobs, final String the_name,
				final String the_district, final String the_region) throws IllegalArgumentException {
		Iterator<Job> jobItr = the_jobs.iterator();
		while (jobItr.hasNext()) {
			my_jobs.add(jobItr.next());
		}
		
		if (the_name == null) {
			throw new IllegalArgumentException("Park name is invalid.");
		} else {
			my_name = the_name;
		}
		
		if (the_district == null) {
			throw new IllegalArgumentException("District is invalid.");
		} else {
			my_district = the_district;
		}
		
		if (the_region == null) {
			throw new IllegalArgumentException("Region is invalid.");
		} else {
			my_region = the_region;
		}
	}
	
	/*
	 * @pre the_name != null
	 * 
	 * @post my_name == the_name
	 */
	/**
	 * Sets the name of the park to the given name.
	 * 
	 * @param the_name The name to set as the name of the park
	 * @throws IllegalArgumentException if the parameter is null
	 */
	public void setParkName(final String the_name) throws IllegalArgumentException {
		if (the_name  == null) {
			throw new IllegalArgumentException("Park name is null.");
		} else {
			my_name = the_name;
		}
	}
	
	/*
	 * @post Returns the name of the park
	 */
	/**
	 * Returns the name of the park.
	 * 
	 * @return Returns the name of the park
	 */
	public String getParkName() {
		return my_name;
	}
	
	/*
	 * @post Returns the district that the park is in
	 */
	/**
	 * Returns the district that the park is in.
	 * 
	 * @return The district that the park is in
	 */
	public String getDistrict() {
		return my_district;
	}
	
	/*
	 * @post Returns the region that the park is in
	 */
	/**
	 * Returns the region that the park is in.
	 * 
	 * @return The region that the park is in
	 */
	public String getRegion() {
		return my_region;
	}
	
	/*
	 * @pre the_job != null
	 * 
	 * @post the_job will be added to this park's list of jobs
	 */
	/**
	 * Adds the given job to this park's list of jobs.
	 * 
	 * @param the_job The job to be added to the park
	 * @throws IllegalArgumentException if the input parameter is null
	 */
	public void addJob(Job the_job) throws IllegalArgumentException {
		if (the_job == null) {
			throw new IllegalArgumentException("Job is invalid.");
		} else {
			my_jobs.add(the_job);
		}
	}
	
	/*
	 * @post Returns all jobs for this park as a collection
	 */
	/**
	 * Returns a Collection of the jobs for this park.
	 * 
	 * @return A Collection of the jobs for this park
	 */
	public Collection<Job> getJobs() {
		return my_jobs;
	}
	
	/*
	 * @pre the_job != null
	 * @pre the_volunteer != null
	 * 
	 * @post the_volunteer will be added to the_job's list of volunteers
	 */
	/**
	 * Adds the given volunteer to the specified job.
	 * 
	 * @param the_job The job to add the volunteer to
	 * @param the_volunteer The volunteer to add to the job
	 * @throws IllegalArgumentException is any of the parameters are null
	 */
	public void addVolunteerToJob(final Job the_job, final Volunteer the_volunteer) 
			throws IllegalArgumentException {
		if (the_job == null) {
			throw new IllegalArgumentException("Job is invalid.");
		} else if (the_volunteer == null) {
			throw new IllegalArgumentException("Volunteer is invalid.");
		} else {
			the_job.addVolunteer(the_volunteer);
		}
	}
	
	/*
	 * @post Returns a String representation of the park.
	 * 		 name	district	region
	 */
	/**
	 * Returns a String representation of the park.
	 * 
	 * @return A String representation of the park.
	 * 		   name district region
	 */
	public String toString() {
		StringBuilder result = new StringBuilder();
		result.append("Name: " + my_name);
		result.append("\tDistrict: " + my_district);
		result.append("\tRegion: " + my_region);
		
		return result.toString();
	}	
}
